import java.util.Scanner;

public class Solution {
    public void duplicateZeros(int[] arr){
        int cur = 0,dest = -1,n = arr.length;
        //先找到最后一个需要复写的数
        while(cur < n){
            if(arr[cur] == 0){
                dest+=2;
            }else{
                dest+=1;
            }
            if(dest>=n-1){
                break;
            }
            cur++;
        }
        //处理一下边界情况
        if(dest == n){
            arr[n-1] = 0;
            cur--;
            dest-=2;
        }
        //从后向前完成复写操作
        while(cur >= 0){
            if(arr[cur] != 0){
                arr[dest--] = arr[cur--];
            }else{
                arr[dest--] = 0;
                arr[dest--] = 0;
                cur--;
            }
        }
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNextInt()){
            int len = in.nextInt();
            int[] array = new int[len];
            for (int i = 0; i < len; i++) {
                array[i] = in.nextInt();
            }
            Solution solution = new Solution();
            solution.duplicateZeros(array);
            for (int i = 0; i < len; i++) {
                System.out.print(array[i]+" ");
            }
        }
    }
}
